package com.cat.twoPointerTechnique;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/move-pieces-to-obtain-a-string/
 * @create 2025/8/6 15:59
 * @since JDK17
 */

public class Solution15 {
    public boolean canChange(String start, String target) {
        int n = start.length();
        for (int i = 0, j = 0; i < n; i++, j++) {
            // 在target中找到第一个不是'_'的字符
            while (i < n && target.charAt(i) == '_') i++;
            while (j < n && start.charAt(j) == '_') j++;
            char a = start.charAt(j), b = target.charAt(i);
            if (a != b) {  // 不相同一定不能实现
                return false;
            }
            if (i < j && b == 'R') {    //
                return false;
            }
            if (i > j && b == 'L') {
                return false;
            }
        }
        return true;
    }
}
